<template>
  <div>
    <el-col :span="8" :offset="8">
      <el-form :span="8" :offset="8" :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
       <el-form-item label="开户账号" prop="account">
          <el-input type="text" v-model="ruleForm.account" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="账号类型" prop="accountType">
          <el-radio v-model="ruleForm.accountType" label="1" border>活期</el-radio>
          <el-radio v-model="ruleForm.accountType" label="2" border>定期</el-radio>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="add">开户</el-button>
          <el-button type="danger" @click="resetForm('ruleForm')">重置</el-button>
          <el-button type="info" @click="returnIndex">返回</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </div>
</template>

<script>
  export default{
    data () {
      var validatePass = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入开户账号'));
        } else {
          callback();
        }
      };

      return {
        ruleForm:{
          account:'',
          accountType:'1'
        },
        rules: {
          account: [
            { validator: validatePass, trigger: 'blur' }
          ]
        }
      };
    },
    methods:{
      add() {
          this.$axios.post("/addAccount",this.ruleForm)
          .then(res=>{
            if(res.data.flag){
              this.$message({
                message: res.data.msg,
                type: 'success'
              });
            }else{
              this.$notify.error({
                title: '错误',
                message: res.data.msg
              });
            }
          })
      },
      resetForm(formName) {
        this.$refs[formName].resetFields();
      },
      returnIndex(){
        this.$router.push("/")
      }
    }
  }
</script>

<style>
</style>
